<%= content_tag(:table, table.attrs) do %>
  <% if table.caption %>
    <%= content_tag(:caption, table.caption.value, table.caption.attrs) %>
  <% end %>
  <% if table.columns.any?{|column| column.attrs.present?} %>
    <% table.columns.chunk{|column| column.attrs}.each do |column_group| %>
      <% span = column_group.last.length %>
      <% attrs = column_group.first %>
      <% attrs.merge!(span: span) if span > 1 %>
      <%= tag(:col, attrs) %>
    <% end %>
  <% end %>
  <thead>
    <tr>
      <% table.columns.each do |column| %>
        <%= tableficate_header_tag(column) %>
      <% end %>
    </tr>
  </thead>
  <tbody>
    <% if table.rows.size > 0 %>
      <% table.rows.each do |row| %>
        <%= tableficate_row_tag(row, table.columns) %>
      <% end %>
    <% elsif table.empty and table.empty.value.present? %>
      <tr><%= content_tag(:td, table.empty.value, table.empty.attrs) %></tr>
    <% end %>
  </tbody>
<% end %>
